package io.renren.modules.dangan.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import io.renren.common.utils.Constant;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.dangan.dao.DaDjgllDao;
import io.renren.modules.dangan.entity.DaDjgllEntity;
import io.renren.modules.dangan.service.DaDjgllService;


@Service("daDjgllService")
public class DaDjgllServiceImpl extends ServiceImpl<DaDjgllDao, DaDjgllEntity> implements DaDjgllService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String th=(String) params.getOrDefault("th","");
        String dh=(String) params.getOrDefault("dh","");
        String zh=(String) params.getOrDefault("zh","");
        String position=(String) params.getOrDefault("position","");
        String landuser=(String) params.getOrDefault("landuser","");
        String szd=(String) params.getOrDefault("szd","");
        String flh= (String) params.getOrDefault("flh","");
        String sFlh= (String) params.getOrDefault("sFlh","");
        String ajh= (String) params.getOrDefault("ajh","");
        String pzwh= (String) params.getOrDefault("pzwh","");
        String bt= (String) params.getOrDefault("bt","");
        if(StringUtils.isNotEmpty(sFlh)){
            flh=sFlh;
        }
        IPage<DaDjgllEntity> page = this.page(
                new Query<DaDjgllEntity>().getPage(params),
                new QueryWrapper<DaDjgllEntity>()
                        .like(StringUtils.isNotBlank(th),"th",th.trim())
                        .like(StringUtils.isNotBlank(dh),"dh",dh.trim())
                        .like(StringUtils.isNotBlank(zh),"zh",zh.trim())
                        .like(StringUtils.isNotBlank(position),"position",position.trim())
                        .like(StringUtils.isNotBlank(landuser),"landuser",landuser.trim())
                        .like(StringUtils.isNotBlank(szd),"gcwz",szd.trim())
                        .like(StringUtils.isNotBlank(ajh),"ajh",ajh.trim())
                        .like(StringUtils.isNotBlank(pzwh),"pzwh",pzwh.trim())
                        .like(StringUtils.isNotBlank(bt),"bt",bt.trim())
                        .like(StringUtils.isNotBlank(flh),"flh",flh)
                .in(CollectionUtil.isNotEmpty((List<String>) params.get(Constant.SQL_SZD_FILTER)),
                        "gcwz",(List)params.get(Constant.SQL_SZD_FILTER))
        );
        return new PageUtils(page);
    }
}
